<!DOCTYPE html>
<html lang="en" xmlns:layout="http://www.w3.org/1999/xhtml"
      layout:decorate="~{commonJs}" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>房源管理</title>
</head>
<body layout:fragment="content">
<div id="addHotelContainerElement">

    <div id="addHotelForm">
        <el-form ref="hotelInfo" :model="hotelInfo" :rules="rules"  label-width="80px">

            <el-form-item label="房源编号" prop="hotelNo">
                <el-input v-model="hotelInfo.hotelNo"></el-input>
            </el-form-item>


            <el-form-item label="房源名称" prop="hotelName">
                <el-input v-model="hotelInfo.hotelName"></el-input>
            </el-form-item>

            <el-form-item style="text-align: center">
                <el-button type="primary" @click="save()">保存</el-button>
                <el-button @click="resetForm('hotelInfo')">重置</el-button>
                <el-button @click="cancel()">取消</el-button>
            </el-form-item>
        </el-form>
    </div>

</div>

<script>
    var vm = new Vue({
        el: '#addHotelContainerElement',
        data: function () {
            var id=top.vm.getVmId();
            var hotelInfo=ajaxGet("/api/hotel/read",{id:id});
            var rules={
                hotelNo:{ required: true, message: '请输入房源编号!', trigger: 'blur' },
                hotelName:{ required: true, message: '请输房源名称!', trigger: 'blur' }
            };
            return {
                hotelInfo: hotelInfo,
                rules:rules
            }
        },
        methods: {
            save: function () {
                this.$refs['hotelInfo'].validate(function(valid) {
                    if (valid) {
                        top.vm.$confirm('确定保存?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'info '
                        }).then(() => {
                            var res=ajaxPost("/api/hotel/save",vm.hotelInfo);
                            if(res == true){
                                top.vm.$message({type: 'success', message: '保存成功!'});
                                vm.closeParentDialog();
                                top.vm.dialogInfo.vm.refresh();
                            }else{
                                top.vm.$message({type: 'success', message: '保存失败!'});
                            }

                        });
                    }
                });
            },
            cancel:function () {
                this.closeParentDialog();
            },
            closeParentDialog:function(){
                top.vm.$data.dialogInfo.dialogVisible=false;
            },
            resetForm:function(formName) {
                this.$refs[formName].resetFields();
            }
        }
    })
</script>
</body>
</html>
